package com.roadjava.rating.service.impl;


import com.roadjava.rating.bean.entity.RatingDO;
import com.roadjava.rating.bean.req.rating.RatingReq;
import com.roadjava.rating.mapper.RatingMapper;
import com.roadjava.rating.service.RatingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RatingServiceImpl implements RatingService {

    @Autowired
    private RatingMapper ratingMapper;

    @Override
    public void addRating(RatingReq rating) {
        ratingMapper.addRating(rating); // 直接通过Mapper添加评分
    }

    @Override
    public void updateRating(Integer ratingId, Integer score) {
        ratingMapper.updateRating(ratingId, score); // 直接通过Mapper更新评分
    }

    @Override
    public void deleteRating(Integer ratingId) {
        ratingMapper.deleteRating(ratingId); // 直接通过Mapper删除评分
    }

    @Override
    public RatingDO getRatingByResourceIdAndUserId(Integer resourceId, Long userId) {
        return ratingMapper.getRatingByResourceIdAndUserId(resourceId, userId); // 直接通过Mapper根据ID查询评分
    }

    @Override
    public Double getAverageRating(Integer resourceId) {
        return ratingMapper.getAverageRating(resourceId); // 直接通过Mapper获取平均评分
    }

    @Override
    public List<RatingDO> getAllRatings() {
        return ratingMapper.getAllRatings(); // 直接通过Mapper获取所有评分
    }

    @Override
    public List<RatingDO> getRatingsByResourceId(Integer resourceId) {
        return ratingMapper.getRatingsByResourceId(resourceId); // 直接通过Mapper获取资源ID的评分
    }

    @Override
    public List<RatingDO> getRatingsByUserId(Long userId) {
        return ratingMapper.getRatingsByUserId(userId); // 直接通过Mapper获取用户ID的评分
    }
}
